//
//  BBSViewListCell.m
//  ChangJia
//
//  Created by 张育铭 on 2019/10/22.
//  Copyright © 2019年 Zhangyuming. All rights reserved.
//

#import "BBSViewListCell.h"

@implementation BBSViewHotCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.headText = [ToolControl creaImagetTitleLabelWithFrame:CGRectMake(30, 0,  SCREEN_WIDTH-50, 30) theImageStr:@"bbs-icon-new" theImageWidth:18 theText:@""];
        [self addSubview:self.headText];
    }
    return self;
}
- (void)setModel:(CJTableViewModel *)model {
    self.headText.text = model.theTitleItem;
}

@end



@implementation BBSViewListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle  = UITableViewCellSelectionStyleNone;
        
        [self.contentView sd_addSubviews:@[self.thePeoplePhoto,self.thePeopleName ,self.tiemBtn,self.theTitleLabel,self.coreTextLabel,self.interlinkageImage,self.picContainerView,self.likeBtn,self.lineImage]];
        
        CGFloat margin = 10;

        self.thePeoplePhoto.sd_layout
        .widthIs (30)
        .heightIs(30)
        .topSpaceToView (self.contentView, 15)
        .leftSpaceToView(self.contentView, 5);
        
        self.thePeopleName.sd_layout
        .topSpaceToView (self.contentView, 15)
        .leftSpaceToView(self.thePeoplePhoto, margin)
        .widthIs (160)
        .heightIs(30);
         
        self.tiemBtn.sd_layout
        .topEqualToView  (self.thePeoplePhoto)
        .rightSpaceToView(self.contentView, margin)
        .widthIs (120)
        .heightIs(18);
        
        self.theTitleLabel.sd_layout
        .topSpaceToView  (self.thePeoplePhoto, margin)
        .leftSpaceToView (self.contentView, margin)
        .rightSpaceToView(self.contentView, margin)
        .heightIs(20);
        
        self.coreTextLabel.sd_layout
        .topSpaceToView  (self.theTitleLabel, margin)
        .leftSpaceToView (self.contentView, margin)
        .rightSpaceToView(self.contentView, margin);

        self.interlinkageImage.sd_layout
        .topSpaceToView (self.theTitleLabel, margin+5)
        .leftSpaceToView(self.contentView, margin+4)
        .widthIs (50)
        .heightIs(50);
         
        self.picContainerView.sd_layout
        .leftEqualToView (self.thePeopleName);
 
        self.likeBtn.sd_layout
        .leftSpaceToView(self.contentView, 0)
        .widthIs (60)
        .heightIs(20);
        
        self.lineImage.sd_layout
        .leftSpaceToView (self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(.8);
        
    }
    return self;
}

- (void)setModel:(CJTableViewModel *)model {
    _model = model;
    [self.thePeoplePhoto sd_setImageWithURL:[NSURL URLWithString:model.thePeoplePhotoItem] placeholderImage:imageName(@"default_user_head")];
    self.thePeopleName.text = model.thePeopleNameItem;
    [self.tiemBtn setTitle:model.theTimeLabelItem forState:(UIControlStateNormal)];
    self.theTitleLabel.text = model.theTitleItem;
    
    
    if ([model.theIsType isEqualToString:@"2"]) {
        self.interlinkageImage.hidden = NO;
        [self.interlinkageImage sd_setImageWithURL:[NSURL URLWithString:model.theInterlinkageImg] placeholderImage:imageName(@"wlj")];

        [self.coreTextLabel text:[NSString stringWithFormat:@"\n                %@",model.theContenLabelItem] customLinks:nil];
        self.coreTextLabel.sd_layout
        .heightIs(60);
        self.coreTextLabel.backgroundColor = RGBCOLOR(244, 244, 244);
        
    } else {
        self.interlinkageImage.hidden = YES;

        [self.coreTextLabel text:model.theContenLabelItem customLinks:nil];
        CGSize size = [self.coreTextLabel sizeThatFits:CGSizeMake([UIScreen mainScreen].bounds.size.width-60, [UIScreen mainScreen].bounds.size.height)];
        if (size.height > 100) {
            self.coreTextLabel.sd_layout
            .heightIs(100);
        } else {
            self.coreTextLabel.sd_layout
            .heightIs(size.height);
        }
    }
//    NSLog(@"%@",(NSArray*)model.thePhotoArray);
    self.picContainerView.picPathStringsArray = (NSArray*)model.thePhotoArray;
    
    CGFloat picContainerTopMargin;
    if (model.thePhotoArray == nil) {
        picContainerTopMargin = 5;
        self.picContainerView.hidden = YES;
    } else {
        picContainerTopMargin = 10;
        self.picContainerView.hidden = NO;
    }
     
    self.picContainerView.sd_layout
    .topSpaceToView(self.coreTextLabel, 5);
    
//  [_tiemBtn setTitle:@"删除" forState:(UIControlStateNormal)];

    [self.likeBtn setTitle:model.theLikecount forState:(UIControlStateNormal)];
    self.likeBtn.sd_layout
    .topSpaceToView(self.picContainerView, 5);

    
    self.lineImage.sd_layout
    .topSpaceToView(self.likeBtn, 10);

    [self setupAutoHeightWithBottomView:self.lineImage bottomMargin:10];
}
- (UIImageView*)thePeoplePhoto {
    if (_thePeoplePhoto == nil) {
        _thePeoplePhoto = [UIImageView new];
        _thePeoplePhoto.layer.cornerRadius  = 15;
        _thePeoplePhoto.layer.masksToBounds = YES;
        _thePeoplePhoto.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _thePeoplePhoto;
}
- (UILabel*)thePeopleName {
    if (_thePeopleName == nil) {
        _thePeopleName = [UILabel new];
        _thePeopleName.font = [UIFont boldSystemFontOfSize:16.0f];
        _thePeopleName.textColor = [UIColor grayColor];
//        _thePeopleName.backgroundColor = [UIColor redColor];
    }
    return _thePeopleName;
}
- (UILabel*)theTitleLabel {
    if (_theTitleLabel == nil) {
        _theTitleLabel = [UILabel new];
        _theTitleLabel.font = [UIFont boldSystemFontOfSize:16.0f];
        _theTitleLabel.textColor = [UIColor blackColor];
    }
    return _theTitleLabel;
}
- (UIButton *)tiemBtn {
    if (_tiemBtn == nil) {
        _tiemBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _tiemBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [_tiemBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [_tiemBtn setImage:imageName(@"bbs_time") forState:UIControlStateNormal];
    }
    return _tiemBtn;
}
- (MYCoreTextLabel*)coreTextLabel {
    if (!_coreTextLabel) {
        _coreTextLabel = [[MYCoreTextLabel alloc]init];
        //创建相关属性的模型
        MYAttributeModel *modelText = [[MYAttributeModel alloc]init];
//        modelText.textFont = [UIFont systemFontOfSize:15.0f]; //设置普通文本大小 , 默认14.f
        _coreTextLabel.attribute = modelText;
        [_coreTextLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)]];
    }
    return _coreTextLabel;
}
- (void)tapImageView {
    _coreTextClick();
}
- (UIImageView*)interlinkageImage {
    if (_interlinkageImage == nil) {
        _interlinkageImage = [UIImageView new];
    }
    return _interlinkageImage;
}

- (PhotoContainer*)picContainerView {
    if (_picContainerView == nil) {
        _picContainerView = [PhotoContainer new];
    }
    return _picContainerView;
}
- (UIButton *)likeBtn {
   if (_likeBtn == nil) {
       _likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
       [_likeBtn setImage:imageName(@"main-chat") forState:UIControlStateNormal];
       [_likeBtn setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateNormal)];
       _likeBtn.titleLabel.font = [UIFont systemFontOfSize:13];
   }
    return _likeBtn;
}
- (UIImageView*)lineImage {
    if (_lineImage == nil) {
        _lineImage = [UIImageView new];
        _lineImage.backgroundColor = RGBCOLOR(244, 244, 244);
    }
    return _lineImage;
}

@end

